package a.autocode.app.maker;

import java.util.HashMap;
import java.util.Map;

import jplat.tools.string.StringUtil;
import a.autocode.JBaseFieldInfo;
import a.autocode.JBaseServiceMaker;
import a.autocode.icop.maker.ICOPConfigInfo;

/**
 * 渠道代码自动生成工具类.
 * @author zhangcq
 * @date Dec 5, 2016
 * @comment
 */
public class AppServiceMaker extends JBaseServiceMaker
{
	//配置文件读取和文件字符集
	public AppServiceMaker( String confpath, String charset )
	{
		super(confpath,charset);
		config = new AppConfigInfo();
	}
	
	/****
	 * 新增解析渠道服务包名。
	 */
	protected boolean parsearseCmd( String name, String value, String value1 )
	{
		AppConfigInfo appConfig = (AppConfigInfo)config;
		
/*		if ( AppConfigInfo.CMD_TRANSCODE.equals(name) )
		{
			appConfig.setBeanName("");
		}*/
		
		return true;
	}
	
	/**
	 * 获取模板值.
	 * 生成文件时,子类可以覆盖该方法指定生成对应的值.
	 * @author zhangcq
	 * @date Dec 12, 2016
	 * @comment
	 * @return
	 */
	protected Map<String,String> getTempKeyValue( JBaseFieldInfo field, String beanName, String type )
	{
		Map<String,String> valMap = new HashMap<String,String>();
		
		//成员域信息.
		StringBuffer fields = new StringBuffer();
		fields.append("\t//").append(field.getDesc()).append("\n");						//注释.
		fields.append("\t").append(field.javaFormat(beanName, type)).append(";\n\n");	//域信息.
		
		//属性信息.
		StringBuffer props = new StringBuffer();
		props.append(field.javaProtertyString(beanName, type));
		
		valMap.put(PL_BEAN_FIELDS, fields.toString() );
		valMap.put(PL_BEAN_PROPS, props.toString() );
		
		return valMap;
	}

	/**
	 * 备份配置文件.
	 * @author zhangcq
	 * @date Jan 13, 2017
	 * @comment
	 */
	public void doPortFileBackup()
	{
		String backupPath = config.getPortBackupPath()+config.getBeanName()+".port";
		if ( StringUtil.isEmpty(backupPath) )
		{
			return;
		}
		
		doPortFileBackup(backupPath);
	}
	
}
